/**
 * 产品添加
 */
var comValidform=null;
var returnStatus=false;
var productInfoAdd={
	dataCache:null,
	
	startEvent:function(){
		$("#recordTab ul").idTabs();
		var proFeatureUE = UE.getEditor('proFeature',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		var proEnsureUE = UE.getEditor('proEnsure',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		var coverCaseUE = UE.getEditor('coverCase',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		var coverFlowUE = UE.getEditor('coverFlow',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/OverseaSafeInfoCtrl/saveOverseaSafeInfo';
				var params = jsUtils.serializeJson($('.com-addForm'));
				
				//先上传图片变成修改
				if($('#proId').val()!=''){
					url = 'mgr/OverseaSafeInfoCtrl/updateOverseaSafeInfo';
					params.id=$('#proId').val();
				}
				
				var proFeature=proFeatureUE.getContent();
				params.proFeatureTxt=proFeature;
				delete params.proFeature;
				
				var proEnsure=proEnsureUE.getContent();
				params.proEnsureTxt=proEnsure;
				delete params.proEnsure;
				
				var coverCase=coverCaseUE.getContent();
				params.coverCaseTxt=coverCase;
				delete params.coverCase;
				
				var coverFlow=coverFlowUE.getContent();
				params.coverFlowTxt=coverFlow;
				delete params.coverFlow;
				
				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode=='200'){
						//关闭窗口并刷新数据
						art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	bindEvent:function(){
		//上传照片
		$('#imageInfo').uploadify({
			'formData' : {},
			'fileTypeDesc' : 'Images',
			'fileTypeExts' : '*.jpg;*.jpeg;*.png;*.bmp;*.gif;*.tiff',
			'sizeLimit' : 5000000,//控制上传文件的大小，单位byte服务器默认只支持30MB(30000000)，修改服务器设置请查看相关资料
			'queueID' : 'queue',
			'swf' : APP_ADDRESS+'js/uploadify/uploadify.swf',
			'uploader' : APP_ADDRESS+'mgr/OverseaSafeInfoCtrl/uploadPic',
			'buttonText' : '上传产品图片',
			'onUploadSuccess' : function(file, data,response) {
				var dataObj = JSON.parse(data);
				if (dataObj) {
					if (dataObj.resultCode == "200") {
						var pic='<a href="'+SERVER_PATH+'photo/'+dataObj.result.proPic+'" target="_blank">'+dataObj.result.proPic+'</a>';
						$('#proId').val(dataObj.result.id);
						$('.com-addForm input[name="proPic"]').val(dataObj.result.proPic);
						$('#filePath').html(pic);
					} else {
						alert(dataObj.msg);
					}
				}
			}
		});
	},
	
	init:function(){
		productInfoAdd.startEvent();
		productInfoAdd.bindEvent();
	}
}
$(document).ready(function() {
	productInfoAdd.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}